package com.uniqueyi.baselib.appbase;

import android.app.Application;
import android.content.Context;

import com.alibaba.android.arouter.launcher.ARouter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.nightfarmer.themer.Themer;
import com.tencent.bugly.crashreport.CrashReport;
import com.uniqueyi.baselib.BuildConfig;
import com.uniqueyi.baselib.R;
import com.uniqueyi.baselib.utilsbase.Utils;

/**
 * Created by
 * author:  cwy.
 * date:    2017/12/25.  10:38.
 * prj:     crxls.
 */


public class BaseApp extends Application {

    public static Context context;
    private final static String TAG = "BaseApplication";

    @Override
    public void onCreate() {
        super.onCreate();
        Themer.INSTANCE.init(this, R.style.def_style);//设置默认主题
        context = this.getApplicationContext();
        Utils.initUitls(context);
        okGo();
        bugly();
        aRouter();
    }

    private void aRouter() {
        if (BuildConfig.DEBUG) {
            //一定要在ARouter.init之前调用openDebug
            ARouter.openDebug();
            ARouter.openLog();
        }
        ARouter.init(this);
    }

    /**
     * okgo
     */
    private void okGo() {
        HttpHeaders headers = new HttpHeaders();
        headers.put("X-Requested-With", "XMLHttpRequest");    //header不支持中文
        OkGo.getInstance().init(this).setRetryCount(3).addCommonHeaders(headers).setCacheTime(60 * 60 * 1000);//设置缓存时间一天
    }

    public void setOkGoDebug() {
    }

    /**
     * 初始化bugly
     */
    private void bugly() {
        CrashReport.initCrashReport(getApplicationContext());
    }

}
